package Thread;

public class ThreadDemo5 {
    static boolean flog = true;
    public static void main(String[] args)  {
        Thread t = new Thread(()->{
           while (!Thread.currentThread().isInterrupted()){
               try {
                   Thread.sleep(500);
               } catch (InterruptedException e) {
                   e.printStackTrace();
                    break;
               }
               System.out.println("线程运行中~~");
           }
            System.out.println("t 线程结束");
        });
        t.start();
        try {
            //睡眠3000ms
            Thread.sleep(3000);
            //将标志位设置为false终止上面的while()
            System.out.println("控制新线程结束");
           t.interrupt();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
